from sqlalchemy import create_engine, Integer, Column, String, DateTime, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import pandas as pd

'''
    http://danielweitzenfeld.github.io/passtheroc/blog/2014/10/12/datasci-sqlalchemy/
'''

engine = create_engine('mysql+pymysql://root:123456@101.200.59.101:3306/opinion', echo=True, pool_size=10)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()


def get_data(sql):
    df = pd.read_sql(sql, con=engine, index_col='EndDate', parse_dates={'EndDate': 'YYYY-MM-DD'})
    print(df)
    # ts = df.resample('m', how='sum').to_period(freq='m')
    # print(ts)


if __name__ == '__main__':
    sql = 'SELECT * FROM LC_MainDataNew WHERE CompanyCode =3 ORDER BY EndDate DESC'
    get_data(sql)
